﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using ToDoApp.DataModels;
using ToDoApp.Web.IDataAdapters.Interfaces;
using ToDoApp.Web.IDataAdapters.Adapters;
using ToDoApp.Web.Models;

namespace ToDoApp.Web.Controllers
{


    //[Authorize]
    public class ValuesController : ApiController
    {
        IToDoAdapter _adapter = new ToDoAdapter();
        // GET api/values
        //public IEnumerable<string> Get()
        public IHttpActionResult Get()
        {

            ToDoIndexVM bucket = new ToDoIndexVM();
            bucket.ToDoList = _adapter.GetAllTodos();

            return Ok(bucket);

        }

        // GET api/values/5
        public IHttpActionResult Get(int id)
        {
            return Ok(_adapter.GetTodo(id));
        }

        // POST api/values
        public IHttpActionResult Post([FromBody]ToDo todo)
        {

            return Ok(_adapter.AddTodo(todo));

        }

        // PUT api/values/5
        //public IHttpActionResult Put(int id, [FromBody]ToDo todo)
        public IHttpActionResult Put([FromBody]ToDo todo)
        {
            return Ok( _adapter.UpdateTodo(todo));
        }

        public IHttpActionResult Put(int id)
        {
            return Ok(_adapter.MarkFinished(id));
        }

        // DELETE api/values/5
        public IHttpActionResult Delete(int id)
        {
            _adapter.DeleteTodo(id);
            return Ok();
        }
    }
}
